package ws.servlet;

import java.rmi.RemoteException;

import org.json.JSONException;
import org.json.JSONObject;

import ws.search.SearchWSProxy;
import cs236369.hw5.SearchWS;

class LocalSearcher implements WSSearcher {

	private final double	locationX;
	private final double	locationY;
	private final double	distance;

	private LocalSearcher(JSONObject object) throws JSONException {
		locationX = object.getDouble("locationX");
		locationY = object.getDouble("locationY");
		distance = object.getDouble("distance");
	}

	public LocalSearcher() {
		// do nothing, default c'tor
		locationX = Double.NaN;
		locationY = Double.NaN;
		distance = Double.NaN;
	}

	@Override
	public LocalSearcher build(JSONObject object) throws JSONException {
		return new LocalSearcher(object);
	}

	@Override
	public String[] search(String endpoint) throws RemoteException {
		SearchWS endpointService = new SearchWSProxy(endpoint);
		String[] serviceResults = endpointService.searchLocal(locationX, locationY, distance);
		return serviceResults;
	}
}
